﻿function showMessagebox(title, message, containerClass, messageType, okHandler, cancelHandler) {
    var container = $('#messagebox-container');
    if (container.length == 1) {
        container.hide();
        container.html('');
    }
    else {
        $("body").append('<div id="messagebox-container"></div>');
        container = $('#messagebox-container');
    }
    container.attr('class', containerClass);

    var contentContainer = '<div id="messagebox-contentcontainer"></div>';
    container.html(contentContainer);

    contentContainer = $('#messagebox-contentcontainer');
    contentContainer.append('<h3>' + (title) + '</h3>');
    contentContainer.append('<p>' + message + '</p>');

    switch (messageType) {
        case 'question':
            contentContainer.append('<div class="input-area-buttons"></div>');
            contentContainer = $('#messagebox-contentcontainer .input-area-buttons');
            contentContainer.append('<input type="button" id="messagebox-container-button-yes" value="Yes" class="input-area-button-submit" />');
            contentContainer.append('<input type="button" id="messagebox-container-button-no" value="No" class="input-area-button" />');
            if (okHandler != 'undefined' && okHandler != null) $('#messagebox-container-button-yes').bind('click', okHandler);
            if (cancelHandler != 'undefined' && cancelHandler != null) $('#messagebox-container-button-no').bind('click', cancelHandler);
            window.setTimeout('$("#messagebox-container-button-yes").focus();', 1000);
            break;
        case 'info':
            contentContainer.append('<div class="input-area-buttons"></div>');
            contentContainer = $('#messagebox-contentcontainer .input-area-buttons');
            contentContainer.append('<input type="button" id="messagebox-container-button-close" value="OK" class="input-area-button-submit" onclick="closeMessagebox();" />');
            if (okHandler != 'undefined' && okHandler != null) $('#messagebox-container-button-close').live('click', okHandler);
            window.setTimeout('$("#messagebox-container-button-close").focus();', 1000);
            break;
    }

    container.show("slide", { direction: "left" }, 500);
}

function closeMessagebox() {
    $('#messagebox-container').hide("slide", { direction: "right" }, 500);
}